From: John Darrington Date: Mon, 4 Jul 2011 15:03:26 +0000 (+0200) Subject: GLM: Prepare the lexer to accept nested variables X-Git-Tag: v0.7.9~206 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df4eeb7d759173fa12eddd067d799e9db9b6bb48;p=pspp-builds.git GLM: Prepare the lexer to accept nested variables --- diff --git a/src/language/stats/glm.c b/src/language/stats/glm.c index f5feab0e..fa418583 100644 --- a/src/language/stats/glm.c +++ b/src/language/stats/glm.c @@ -654,6 +654,20 @@ static bool parse_design_interaction (struct lexer *lexer, struct glm_spec *glm) { const struct variable *v = NULL; + switch (lex_next_token (lexer, 1)) + { + case T_ENDCMD: + case T_SLASH: + case T_COMMA: + case T_ID: + case T_BY: + case T_ASTERISK: + break; + default: + return false; + break; + } + if (! lex_match_variable (lexer, glm, &v)) return false; @@ -670,20 +684,36 @@ parse_design_interaction (struct lexer *lexer, struct glm_spec *glm) return true; } -/* A design term is a varible OR an interaction */ static bool -parse_design_term (struct lexer *lexer, struct glm_spec *glm) +parse_nested_variable (struct lexer *lexer, struct glm_spec *glm) { const struct variable *v = NULL; - if (parse_design_interaction (lexer, glm)) - return true; + if ( ! lex_match_variable (lexer, glm, &v)) + return false; - /* FIXME: This should accept nexted variables */ - if ( lex_match_variable (lexer, glm, &v)) + if (lex_match (lexer, T_LPAREN)) { - return true; + if ( ! parse_nested_variable (lexer, glm)) + return false; + + if ( ! lex_force_match (lexer, T_RPAREN)) + return false; } + lex_error (lexer, "Nested variables are not yet implemented"); return false; + return true; +} + +/* A design term is an interaction OR a nested variable */ +static bool +parse_design_term (struct lexer *lexer, struct glm_spec *glm) +{ + if (parse_design_interaction (lexer, glm)) + return true; + + if ( parse_nested_variable (lexer, glm)) + return true; + return false; } @@ -696,7 +726,6 @@ parse_design_term (struct lexer *lexer, struct glm_spec *glm) static bool parse_design_spec (struct lexer *lexer, struct glm_spec *glm) { - /* Kludge: Return success if end of design spec */ if (lex_token (lexer) == T_ENDCMD || lex_token (lexer) == T_SLASH) return true;