📄 parser.c
字号:
/*Copyright (c) 2000, Red Hat, Inc.This file is part of Source-Navigator.Source-Navigator is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public License as publishedby the Free Software Foundation; either version 2, or (at your option)any later version.Source-Navigator is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith Source-Navigator; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*//* $Id: Parser.c,v 1.1.1.1 2002/04/18 23:42:03 mdejong Exp $ */#include "Parser.h"#ifdef __cplusplusextern "C" {#include "Reuse.h"#include "rMemory.h"#include "General.h"#include "DynArray.h"#ifndef NO_RECOVER#include "Sets.h"#endif#if ! defined NO_RECOVER | defined YYReParse#include "Errors.h"#endif#if defined YYDEBUG | defined lex_interface#include "Position.h"#endif#include <stdio.h>#include <string.h>}#else#include "Reuse.h"#include "rMemory.h"#include "General.h"#include "DynArray.h"#ifndef NO_RECOVER#include "Sets.h"#endif#if ! defined NO_RECOVER | defined YYReParse#include "Errors.h"#endif#if defined YYDEBUG | defined lex_interface#include "Position.h"#endif#include <stdio.h>#endif#ifdef lex_interface#define GetToken yylex extern int yylex ARGS ((void));#ifndef AttributeDef#include "Position.h" typedef struct { tPosition Position; } tScanAttribute; tScanAttribute Attribute = {{ 0, 0 }};#endif#ifndef ErrorAttributeDef#define ErrorAttribute(Token, RepairAttribute)#endif#ifndef yyGetAttribute#define yyGetAttribute(yyAttrStackPtr, a) * yyAttrStackPtr = yylval#endif#else#include "Scanner.h"#ifndef yyGetAttribute#define yyGetAttribute(yyAttrStackPtr, a) (yyAttrStackPtr)->Scan = a#endif#endiftypedef unsigned short yyStateRange ;typedef unsigned short yySymbolRange ;typedef struct { yyStateRange Check, Next; } yytComb;typedef enum {yyNT0_intern = 16,yyNTprogram = 17,yyNTstatements = 18,yyNTstatement = 19,yyNTwords = 20,yyNTword = 21,yyNTqualification = 22,yyNTlocal_qualification = 23,yyNTglobal_qualification = 24,yyNTfragments = 25,yyNTfragment = 26,yyNTvariable = 27,yyNTsimple_local_qual = 28,yyNTsimple_global_qual = 29,yyNTend = 30} yytNonterminal;typedef struct { short yyMode; rbool yyActions, yyMessages; } yytControl;static yytControl yyControl = { 0, rtrue, rtrue }; rbool Parser_Debug = rfalse;#define yyFirstTerminal 0#define yyLastTerminal 15#define yySetSize 16#define yyFirstSymbol 0#define yyLastSymbol 30#define yyTTableMax 301#define yyNTableMax 59#define yyStartState 1#define yyFirstReadState 1#define yyLastReadState 42#define yyFirstReadReduceState 43#define yyLastReadReduceState 64#define yyFirstReduceState 65#define yyLastReduceState 127#define yyLastState 127#define yyLastStopState 65#define YYTDefault#define YYNDefault#define yyFirstFinalState yyFirstReadReduceState#define ErrorMessages(Messages) yyControl.yyMessages = Messages#define SemActions(Actions) yyControl.yyActions = Actions#ifdef YYGetLook#define GetLookahead(k) yyGetLookahead ((k) - 1, yyTerminal)#define GetAttribute(k, a) xxGetAttribute ((k) - 1, yyTerminal, a)static int yyGetLookahead ARGS ((int yyk, yySymbolRange yyToken));static void xxGetAttribute ARGS ((int yyk, yySymbolRange yyToken, tScanAttribute * yyAttribute));#endif/* line 16 "Parser.lrk" */#include <stdlib.h>#include "Tree.h"#include "Position.h"#include "Eval.h"#include "Trafo.h"#include "itcl.h"#define fprintf(x,y)extern FILE * cross_ref_fp ; int tcl80, itcl, itcl15; FILE * yyin ; FILE * hlfp ; int hl ; char * current_file ;static rbool is_initialized = rfalse;static rbool report = rfalse;static rbool graphic = rfalse;static tIdent i_lparent, i_rparent;static int dialect ;static void get_options ARGS ((void)){ char * arg = getenv ("PAF_TCL"); if (arg == NULL) return; while (* arg) { if (* arg == '-') { switch (* ++ arg) { case 'f': report = rtrue; break; case 'g': graphic = rtrue; break; case 'h': (void) printf ("\nsyntax of PAF_TCL:\n\n"); (void) printf (" [-f] [-h]\n\n"); (void) printf (" f : report error messages (default: do not report)\n"); (void) printf (" h : help\n\n"); break; } } arg ++; }}void start_parser (fname, parse_cplpl, highl_fp, highlight) char * fname; int parse_cplpl; FILE * highl_fp; int highlight;{ current_file = fname; hlfp = highl_fp; hl = highlight; tcl80 = itcl = itcl15 = 0; if (! is_initialized) { get_options (); is_initialized = rtrue; } StoreMessages (rtrue); InitStringMemory (); InitIdents (); if (fname) Attribute.Position.FileName = MakeIdent (fname, strlen (fname)); else Attribute.Position.FileName = NoIdent; BeginFile (""); Beginitcl (); BeginTrafo (); (void) Parser (); /* CheckTree (TreeRoot); */ Eval (TreeRoot); itcl += itcl15; if (itcl > 0 && tcl80 > 0) { Interpret_tcl (TreeRoot); fprintf (stderr, "???\n"); } else if (tcl80 > 0) { Interpret_tcl (TreeRoot); fprintf (stderr, "tcl\n"); } else if (itcl > 0) { if (itcl15 > 0) { Interpret_itcl (TreeRoot); fprintf (stderr, "itcl15\n"); } else { Interpret_itcl (TreeRoot); fprintf (stderr, "itcl22\n"); } } else { Interpret_tcl (TreeRoot); fprintf (stderr, "zero\n"); }#ifdef DRAWTREE if (graphic) DrawTree (TreeRoot);#endif if (report) WriteMessages (stderr); CloseStringMemory (); ReleaseTreeModule ();}#define SHARE#ifdef DRAWTREE#undef SHARE#endif#ifdef SHAREstatic tTree snostmt, snoword, snotext;#define dnostmt snostmt#define dnoword snoword#define dnotext snotext#else#define dnostmt mnostmt ()#define dnoword mnoword ()#define dnotext mnotext ()#endiftypedef struct { tTree tree; } zzstatements;typedef struct { tTree tree; } zzstatement;typedef struct { tTree tree; } zzwords;typedef struct { tTree tree; } zzword;typedef struct { tTree tree; } zzqualification;typedef struct { tTree tree; } zzlocal_qualification;typedef struct { tTree tree; } zzglobal_qualification;typedef struct { tTree tree; rbool is_simple; } zzfragments;typedef struct { tTree tree; rbool is_simple; } zzfragment;typedef struct { tTree tree; } zzvariable;typedef struct { tTree tree; } zzsimple_local_qual;typedef struct { tTree tree; } zzsimple_global_qual;typedef union {tScanAttribute Scan;zzstatements statements;zzstatement statement;zzwords words;zzword word;zzqualification qualification;zzlocal_qualification local_qualification;zzglobal_qualification global_qualification;zzfragments fragments;zzfragment fragment;zzvariable variable;zzsimple_local_qual simple_local_qual;zzsimple_global_qual simple_global_qual;} tParsAttribute;#if defined lex_interface & ! defined yylvalDef tParsAttribute yylval;#endif#ifndef yyInitStackSize#define yyInitStackSize 100#endif#ifndef MY_ERROR#define MY_ERROR#endif#define yyNoState 0#define yystandard 1#define yytrial 2#define yybuffer 4#define yyreparse 8#define yyS yySynAttribute#define yyA yyAttrStackPtr#define YYACCEPT goto yyAccept#define YYABORT goto yyAbort#ifdef YYDEC_TABLE#define yyDecrement(x)#define yySetNT(x)#else#define yyDecrement(x) yyStateStackPtr -= x; yyAttrStackPtr -= x;#define yySetNT(x) yyNonterminal = x;#endif#ifdef YYNDefault#define yytNComb yytComb#else#define yytNComb yyStateRange#endif#if defined YYDEBUG | defined YYDCRPstatic long yyCount = 0;static FILE * yyTrace ;static void yyPrintState ARGS ((yyStateRange yyState));static void yyNl ARGS ((void));static char * yyRule [] = { 0,""};#endif char * Parser_TokenName [yyLastTerminal + 2] = {"_EOF_","ident","character","$","\"(","\")","[","]","{","}","::","(",")","space","EOF","end_of_command",""};static yytComb yyTComb [yyTTableMax + 1] = {{ 9, 65}, { 20, 114}, { 20, 114}, { 20, 114}, { 20, 114}, { 10, 67}, { 20, 114}, { 10, 67}, { 20, 114}, { 10, 67}, { 20, 35}, { 20, 36}, { 20, 114}, { 20, 114}, { 20, 114}, { 20, 114}, { 39, 80}, { 39, 80}, { 39, 80}, { 39, 80}, { 21, 51}, { 39, 80}, { 22, 52}, { 39, 80}, { 32, 54}, { 39, 80}, { 39, 80}, { 39, 45}, { 39, 80}, { 39, 80}, { 39, 80}, { 19, 110}, { 19, 110}, { 19, 110}, { 19, 110}, { 23, 53}, { 19, 110}, { 0, 0}, { 19, 110}, { 0, 0}, { 19, 33}, { 19, 34}, { 19, 110}, { 19, 110}, { 19, 110}, { 19, 110}, { 18, 59}, { 18, 109}, { 18, 109}, { 18, 109}, { 0, 0}, { 18, 109}, { 0, 0}, { 18, 109}, { 0, 0}, { 18, 109}, { 18, 109}, { 18, 109}, { 18, 109}, { 18, 109}, { 18, 109}, { 33, 58}, { 33, 120}, { 33, 120}, { 33, 120}, { 0, 0}, { 33, 120}, { 0, 0}, { 33, 120}, { 0, 0}, { 33, 120}, { 33, 120}, { 33, 120}, { 33, 120}, { 33, 120}, { 33, 120}, { 35, 60}, { 35, 123}, { 35, 123}, { 35, 123}, { 0, 0}, { 35, 123}, { 0, 0}, { 35, 123}, { 0, 0}, { 35, 123}, { 35, 123}, { 35, 123}, { 35, 123}, { 35, 123}, { 35, 123}, { 25, 91}, { 25, 91}, { 25, 91}, { 25, 91}, { 0, 0}, { 25, 91}, { 0, 0}, { 25, 91}, { 0, 0}, { 25, 91}, { 25, 91}, { 25, 48}, { 25, 91}, { 25, 91}, { 25, 91}, { 14, 82}, { 14, 82}, { 14, 82}, { 14, 82}, { 0, 0}, { 14, 82}, { 0, 0}, { 14, 82}, { 0, 0}, { 14, 30}, { 14, 31}, { 14, 82}, { 14, 82}, { 14, 82}, { 14, 82}, { 13, 78}, { 13, 78}, { 13, 78}, { 13, 78}, { 0, 0}, { 13, 78}, { 0, 0}, { 13, 78}, { 0, 0}, { 13, 28}, { 13, 29}, { 13, 78}, { 13, 78}, { 13, 78}, { 13, 78}, { 2, 57}, { 2, 101}, { 2, 101}, { 2, 101}, { 0, 0}, { 2, 101}, { 0, 0}, { 2, 17}, { 0, 0}, { 2, 18}, { 2, 101}, { 2, 101}, { 2, 101}, { 2, 101}, { 2, 101}, { 37, 88}, { 37, 88}, { 37, 88}, { 37, 88}, { 0, 0}, { 37, 88}, { 0, 0}, { 37, 88}, { 0, 0}, { 37, 88}, { 37, 88}, { 37, 47}, { 37, 88}, { 37, 88}, { 37, 88}, { 42, 116}, { 42, 116}, { 42, 116}, { 42, 116}, { 0, 0}, { 42, 116}, { 0, 0}, { 42, 116}, { 0, 0}, { 42, 116}, { 42, 116}, { 42, 56}, { 42, 116}, { 42, 116}, { 42, 116}, { 41, 112}, { 41, 112}, { 41, 112}, { 41, 112}, { 0, 0}, { 41, 112}, { 0, 0}, { 41, 112}, { 0, 0}, { 41, 112}, { 41, 112}, { 41, 55}, { 41, 112}, { 41, 112}, { 41, 112}, { 40, 84}, { 40, 84}, { 40, 84}, { 40, 84}, { 0, 0}, { 40, 84}, { 0, 0}, { 40, 84}, { 0, 0}, { 40, 84}, { 40, 84}, { 40, 46}, { 40, 84}, { 40, 84}, { 40, 84}, { 8, 50}, { 8, 49}, { 8, 2}, { 8, 3}, { 0, 0}, { 8, 4}, { 0, 0}, { 8, 5}, { 0, 0}, { 8, 6}, { 8, 7}, { 8, 43}, { 0, 0}, { 8, 62}, { 8, 64}, { 30, 98}, { 30, 98}, { 30, 98}, { 30, 98}, { 30, 98}, { 30, 98}, { 15, 99}, { 15, 99}, { 15, 99}, { 15, 99}, { 15, 99}, { 15, 99}, { 28, 95}, { 28, 95}, { 28, 95}, { 28, 95}, { 28, 95}, { 28, 95}, { 6, 86}, { 6, 24}, { 6, 86}, { 6, 86}, { 6, 86}, { 6, 86}, { 7, 90}, { 7, 90}, { 7, 90}, { 7, 90}, { 36, 115}, { 36, 115}, { 36, 115}, { 36, 115}, { 4, 67}, { 24, 87}, { 24, 87}, { 24, 87}, { 24, 87}, { 3, 67}, { 4, 8}, { 4, 61}, { 4, 63}, { 34, 111}, { 34, 111}, { 34, 111}, { 34, 111}, { 3, 8}, { 3, 61}, { 3, 63}, { 31, 83}, { 31, 83}, { 31, 83}, { 31, 83}, { 17, 67}, { 1, 67}, { 0, 0}, { 0, 0}, { 17, 8}, { 17, 61}, { 17, 63}, { 38, 44}, { 38, 73}, { 38, 73}, { 38, 73}, { 12, 72}, { 12, 72}, { 12, 72}, { 1, 8}, { 1, 61}, { 1, 63}, { 29, 79}, { 29, 79}, { 29, 79}, { 29, 79}, { 26, 27}, { 26, 61}, { 26, 63}, };static yytNComb yyNComb [yyNTableMax - yyLastTerminal] = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -