From b0aa8043649cbce60480011d9b994caad5641158 Mon Sep 17 00:00:00 2001 From: redbrain Date: Sun, 15 Aug 2010 03:27:00 +0100 Subject: [PATCH] parser cleanups --- gcc/python/lexer.l | 17 ++++++++++++----- gcc/python/parser.y | 53 ++++++++++++++++++++++++++++++++++++++++++++++------ gcc/python/symbols.h | 6 ++++-- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/gcc/python/lexer.l b/gcc/python/lexer.l index dcea1fb0c38..bf250adac30 100644 --- a/gcc/python/lexer.l +++ b/gcc/python/lexer.l @@ -38,15 +38,19 @@ along with GCC; see the file COPYING3. If not see #include "langhooks-def.h" #include "target.h" +#include +#include + #include "vec.h" +#include "hashtab.h" #include "gpy.h" -#include "symbols.h" #include "opcodes.def" -#include "y.py.h" +#include "symbols.h" +#include "pypy-tree.h" +#include "runtime.h" -#include -#include +#include "y.py.h" /* Stack required for INDENT and DEDENT tokens @see * - http://docs.python.org/reference/lexical_analysis.html @@ -110,6 +114,9 @@ else { return ELSE; } "and" { return AND; } "not" { return NOT; } +"True" { return V_TRUE; } +"False" { return V_FALSE; } + {qstring} { yylval.string= xstrdup( (yytext+1) ); if( yylval.string[ yyleng-2 ] != '\"' ) { @@ -126,7 +133,7 @@ else { return ELSE; } mpfr_init2( x, 32 ); if( mpfr_set_str( x, yytext, 10, GMP_RNDU) ) { - error("error initilizing integer value <%s>!\n", yytext ); + fatal_error("error initilizing integer value <%s>!\n", yytext ); } yylval.integer = mpfr_get_si( x, GMP_RNDU ); mpfr_clear( x ); diff --git a/gcc/python/parser.y b/gcc/python/parser.y index c4b6bc0ecb2..08f3196e166 100644 --- a/gcc/python/parser.y +++ b/gcc/python/parser.y @@ -36,15 +36,17 @@ along with GCC; see the file COPYING3. If not see #include "langhooks-def.h" #include "target.h" +#include +#include + #include "vec.h" +#include "hashtab.h" #include "gpy.h" -#include "symbols.h" #include "opcodes.def" -#include "line-map.h" - -#include -#include +#include "symbols.h" +#include "pypy-tree.h" +#include "runtime.h" static VEC( gpy_sym,gc ) * gpy_symbol_stack; @@ -81,6 +83,9 @@ extern void yyerror( const char * ); %token AND "and" %token NOT "not" +%token V_TRUE "True" +%token V_FALSE "False" + %token NEWLINE %token INDENT %token DEDENT @@ -96,6 +101,7 @@ extern void yyerror( const char * ); %token IDENTIFIER %token STRING %token INTEGER +%token DOUBLE %type statement %type compound_stmt @@ -325,7 +331,6 @@ target: IDENTIFIER ; expression_list: expression - { $$ = $1; } ; expression: conditional_expression @@ -417,6 +422,42 @@ literal: INTEGER sym->op_a.integer= $1; $$= sym; } + | STRING + { + gpy_symbol_obj *sym; + Gpy_Symbol_Init( sym ); + + sym->exp = OP_EXPRESS; + sym->type= SYMBOL_PRIMARY; + sym->op_a_t= TYPE_STRING; + + sym->op_a.string= $1; + $$= sym; + } + | V_TRUE + { + gpy_symbol_obj *sym; + Gpy_Symbol_Init( sym ); + + sym->exp = OP_EXPRESS; + sym->type= SYMBOL_PRIMARY; + sym->op_a_t= TYPE_BOOLEAN; + + sym->op_a.boolean= true; + $$= sym; + } + | V_FALSE + { + gpy_symbol_obj *sym; + Gpy_Symbol_Init( sym ); + + sym->exp = OP_EXPRESS; + sym->type= SYMBOL_PRIMARY; + sym->op_a_t= TYPE_BOOLEAN; + + sym->op_a.boolean= false; + $$= sym; + } ; atom: target diff --git a/gcc/python/symbols.h b/gcc/python/symbols.h index 43fa2cf8150..b83e911f40a 100644 --- a/gcc/python/symbols.h +++ b/gcc/python/symbols.h @@ -25,13 +25,15 @@ typedef struct GTY(()) gpy_symbol_table_t { location_t loc; union { /* literal primitive semantic types! */ - long int integer; + int integer; char * string; + bool boolean; struct gpy_symbol_table_t * symbol_table; } op_a; union { - long int integer; + int integer; char * string; + bool boolean; struct gpy_symbol_table_t * symbol_table; } op_b; struct gpy_symbol_table_t *next; -- 2.11.4.GIT