# # # The Nim Compiler # (c) Copyright 2015 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # # This module implements the parser of the standard Nim syntax. # The parser strictly reflects the grammar ("doc/grammar.txt"); however # it uses several helper routines to keep the parser small. A special # efficient algorithm is used for the precedence levels. The parser here can # be seen as a refinement of the grammar, as it specifies how the AST is built # from the grammar and how comments belong to the AST. # In fact the grammar is generated from this file: when isMainModule: # Leave a note in grammar.txt that it is generated: #| # This file is generated by compiler/parser.nim. import pegs var outp = open("doc/grammar.txt", fmWrite) for line in lines("compiler/parser.nim"): if line =~ peg" \s* '#| ' {.*}": outp.write matches[0], "\L" outp.close import llstream, lexer, idents, strutils, ast, msgs, options, lineinfos, pathutils when defined(nimpretty): import layouter type TParser* = object # A TParser object represents a file that # is being parsed currInd: int # current indentation level firstTok: bool # Has the first token been read? hasProgress: bool # some while loop requires progress ensurance lex*: TLexer # The lexer that is used for parsing tok*: TToken # The current token inPragma*: int # Pragma level inSemiStmtList*: int emptyNode: PNode when defined(nimpretty): em*: Emitter SymbolMode = enum smNormal, smAllowNil, smAfterDot TPrimaryMode = enum pmNormal, pmTypeDesc, pmTypeDef, pmSkipSuffix proc parseAll*(p: var TParser): PNode proc closeParser*(p: var TParser) proc parseTopLevelStmt*(p: var TParser): PNode # helpers for the other parsers proc isOperator*(tok: TToken): bool proc getTok*(p: var TParser) proc parMessage*(p: TParser, msg: TMsgKind, arg: string = "") proc skipComment*(p: var TParser, node: PNode) proc newNodeP*(kind: TNodeKind, p: TParser): PNode proc newIntNodeP*(kind: TNodeKind, intVal: BiggestInt, p: TParser): PNode proc newFloatNodeP*(kind: TNodeKind, floatVal: BiggestFloat, p: TParser): PNode proc newStrNodeP*(kind: TNodeKind, strVal: string, p: TParser): PNode proc newIdentNodeP*(ident: PIdent, p: TParser): PNode proc expectIdentOrKeyw*(p: TParser) proc expectIdent*(p: TParser) proc parLineInfo*(p: TParser): TLineInfo proc eat*(p: var TParser, tokType: TTokType) proc skipInd*(p: var TParser) proc optPar*(p: var TParser) proc optInd*(p: var TParser, n: PNode) proc indAndComment*(p: var TParser, n: PNode) proc setBaseFlags*(n: PNode, base: TNumericalBase) proc parseSymbol*(p: var TParser, mode = smNormal): PNode proc parseTry(p: var TParser; isExpr: bool): PNode proc parseCase(p: var TParser): PNode proc parseStmtPragma(p: var TParser): PNode proc parsePragma(p: var TParser): PNode proc postExprBlocks(p: var TParser, x: PNode): PNode proc parseExprStmt(p: var TParser): PNode proc parseBlock(p: var TParser): PNode proc primary(p: var TParser, mode: TPrimaryMode): PNode proc simpleExprAux(p: var TParser, limit: int, mode: TPrimaryMode): PNode # implementation template prettySection(body) = when defined(nimpretty): beginSection(p.em) body when defined(nimpretty): endSection(p.em) proc getTok(p: var TParser) = ## Get the next token from the parser's lexer, and store it in the parser's ## `tok` member. rawGetTok(p.lex, p.tok) p.hasProgress = true when defined(nimpretty): emitTok(p.em, p.lex, p.tok) # skip the additional tokens that nimpretty needs but the parser has no # interest in: while p.tok.tokType == tkComment: rawGetTok(p.lex, p.tok) emitTok(p.em, p.lex, p.tok) proc openParser*(p: var TParser, fileIdx: FileIndex, inputStream: PLLStream, cache: IdentCache; config: ConfigRef) = ## Open a parser, using the given arguments to set up its internal state. ## initToken(p.tok) openLexer(p.lex, fileIdx, inputStream, cache, config) when defined(nimpretty): openEmitter(p.em, cache, config, fileIdx) getTok(p) # read the first token p.firstTok = true p.emptyNode = newNode(nkEmpty) proc openParser*(p: var TParser, filename: AbsoluteFile, inputStream: PLLStream, cache: IdentCache; config: ConfigRef) = openParser(p, fileInfoIdx(config, filename), inputStream, cache, config) proc closeParser(p: var TParser) = ## Close a parser, freeing up its resources. closeLexer(p.lex) when defined(nimpretty): closeEmitter(p.em) proc parMessage(p: TParser, msg: TMsgKind, arg = "") = ## Produce and emit the parser message `arg` to output. lexMessageTok(p.lex, msg, p.tok, arg) proc parMessage(p: TParser, msg: string, tok: TToken) = ## Produce and emit a parser message to output about the token `tok` parMessage(p, errGenerated, msg % prettyTok(tok)) proc parMessage(p: TParser,
#ifndef PONG_H
#define PONG_H
#define MOUSE_LEFT_BUTTON MOUSE_BUTTON_LEFT
#include <raylib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_audio.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include <SDL2/SDL_atomic.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <time.h>
#include <setjmp.h>
#include <string.h>
#include <stdint.h>
#include "sounds.h"
#define LEFT 0
#define RIGHT 1
struct Players {
float Y;
Rectangle HitBox;
int Score;
int Direction;
Rectangle BallDetector;
int NextTick;
};
struct Balls {
float X;
float Y;
float Angle;
float Speed;
int Direction;
Rectangle HitBox;
int NextTick;
};
struct Settings {
int SoundVolume;
int MusicVolume;
int Fullscreen;
};
extern struct Settings GlobalSettings;
extern int Difficulty;
extern bool GameGoing;
extern SDL_atomic_t Ticks;
extern char VersionString[256];
extern SDL_atomic_t AudioInitializing;
void enemy(struct Players *Enemy, struct Balls ball);
void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerScore, int *EnemyScore);
bool play_audio(int SoundEffect);
int title_screen();
void versus_main();
void marathon_main();
void set_screen_mode();
#endif