Skip to content

Instantly share code, notes, and snippets.

@ponyatov
Last active August 18, 2016 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ponyatov/bfc2134eb58fb18046e3b350eaf9adf6 to your computer and use it in GitHub Desktop.
Save ponyatov/bfc2134eb58fb18046e3b350eaf9adf6 to your computer and use it in GitHub Desktop.
parser-enabled program required #includes
#ifndef _H_HPP
#define _H_HPP
// required includes
#include <iostream>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
#include "meta.hpp"
// algebraic data type (base class)
struct Sym {
string tag; // item class/type/tag
string val; // item value (can be any type in inherited classes + head() overloaded)
Sym(string,string); // tag:value constructor
Sym(string); // lexer constructor (see TAG() macro)
vector<Sym*> nest; void push(Sym*); // Sym object can store <nested elements>
virtual string dump(int=0); // \ dump Sym object in nested tree form
virtual string head(); // <T:V> header
string pad(int); // / tree padding function
}
extern map<string,Sym*> glob; // global symbol table
extern void glob_init();
// lexer/parser interface
extern int yylex();
extern int yylineno;
extern char* yytext;
#define TOC(C,X) { yylval.o = new C(yytext); return X; }
extern int yyparse();
extern void yyerror(string);
#include "ypp.tab.hpp"
#endif // _H_HPP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment